home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Deutsche Edition 1
/
Deutsche Edition 1.iso
/
amok
/
amok_lha
/
amok24.lha
/
DME
/
SRC
/
source.zoo
/
subs.c
< prev
next >
Wrap
C/C++ Source or Header
|
1989-07-03
|
5KB
|
275 lines
/*
* SUBS.C
*
* (C)Copyright 1987 by Matthew Dillon, All Rights Reserved
*
* Subroutines.
*/
#include "defs.h"
extern PROC *proc;
/*
* Create DME's text icon.
*/
makemygadget(gad)
register struct Gadget *gad;
{
static unsigned long ga[] = {
0xFFFFFFFF, /* 32 pixels across */
0x80FDCBFD,
0xFFFDDFFD,
0x80000001,
0x80DFDDDF,
0x80000001,
0xBC0EF00B,
0x80000001,
0xBFC00CDD,
0x80000001,
0xA00DF00F,
0x80000001,
0x80000001,
0x80000001,
0x80FDCBFD,
0xFFFDDFFD,
0x80000001,
0x80DFDDDF,
0x80000001,
0xBC0EF00B,
0x80000001,
0xBFC00CDD,
0x80000001,
0xA00DF00F,
0x80000001,
0xFFFFFFFF
};
static struct Image image = {
0, 0, 20, sizeof(ga)/4/2, 2, (unsigned short *)ga, 3, 0, NULL
};
bzero(gad, sizeof(struct Gadget));
gad->Width = 20;
gad->Height = sizeof(ga)/4/2 + 1;
gad->Flags = GADGIMAGE|GADGHCOMP;
gad->GadgetType = BOOLGADGET;
gad->Activation = RELVERIFY|GADGIMMEDIATE;
gad->GadgetRender = (APTR)ℑ
}
/*
* return index of first non space. Returns 0 if no spaces found.
*/
firstns(str)
register char *str;
{
register short i;
for (i = 0; str[i] && str[i] == ' '; ++i);
if (str[i] == 0)
i = 0;
return(i);
}
/*
* Return index of last non-space, 0 if no spaces.
*/
lastns(str)
register char *str;
{
register short i;
for (i = strlen(str) - 1; i > 0 && str[i] == ' '; --i);
if (i < 0)
i = 0;
return(i);
}
/*
* Return length of word under cursor
*/
wordlen(str)
register char *str;
{
register short i;
for (i = 0; *str && *str != ' '; ++i, ++str);
return(i);
}
/*
* Find the path from some root device to a specific filename (src), and
* stick the result in (dest). If unable to backtrace along directories,
* simply copy (src) into (dest)
*
* Returns (1) if able to backtrace, (0) if not.
*/
getpath(src, dest)
char *src, *dest;
{
register long flock, pflock;
register short len, total;
register FIB *fib = (FIB *)malloc(sizeof(FIB));
char c;
dest[0] = 0;
total = 1;
proc->pr_WindowPtr = (APTR)Ep->Win;
flock = Lock(src, ACCESS_READ);
if (flock == NULL) { /* missing file? */
for (len = strlen(src); len >= 0; --len) {
if (src[len] == '/') {
--len;
break;
}
if (src[len] == ':')
break;
}
if (c = src[len + 1]) {
strcpy(dest, src+len+2);
total = strlen(dest)+1;
}
src[len + 1] = 0;
flock = Lock(src, ACCESS_READ);
src[len + 1] = c;
}
if (flock) {
do {
pflock = ParentDir(flock);
if (Examine(flock, fib) == 0)
fib->fib_FileName[0] = 0;
if (fib->fib_FileName[0] == 0)
strcpy(fib->fib_FileName, "ram");
len = strlen(fib->fib_FileName);
bmov(dest, dest + len + 1, total);
dest[len] = (pflock) ? '/' : ':';
bmov(fib->fib_FileName, dest, len);
total += len + 1;
UnLock(flock);
flock = pflock;
} while(pflock);
len = strlen(dest) - 1;
if (dest[len] == '/')
dest[len] = 0;
return(1);
}
strcpy(dest, src);
return(0);
}
int
is_ascii(chr)
char chr;
{
register ch = chr;
if( (ch >= '0' && ch <= '9') ||
(ch >= 'A' && ch <= 'Z') ||
(ch >= 'a' && ch <= 'z') ||
ch == '_'
)
return -1;
else
return 0;
}
/*
* Allocation routines and other shortcuts
*/
ubyte *
allocb(bytes)
{
return(AllocMem(bytes, MEMF_CLEAR|MEMF_PUBLIC));
}
ubyte *
allocl(lwords)
{
return(AllocMem(lwords<<2, MEMF_CLEAR|MEMF_PUBLIC));
}
bmovl(s,d,n)
char *s,*d;
{
bmov(s,d,n<<2);
}
/*
* Remove tabs in a buffer
*/
detab(ibuf, obuf, maxlen)
register char *ibuf, *obuf;
{
register short i, j;
maxlen -= 2;
for (i = j = 0; ibuf[i] && j < maxlen; ++i) {
if (ibuf[i] == 9) {
do {
obuf[j++] = ' ';
} while ((j & 7) && j < maxlen);
} else {
obuf[j++] = ibuf[i];
}
}
while (j && obuf[j-1] == ' ')
--j;
obuf[j] = 0;
return(j);
}
xefgets(xfi, buf, max)
char *buf;
long xfi;
{
char ebuf[256];
if (xfgets(xfi, ebuf, max) >= 0)
return(detab(ebuf, buf, max));
return(-1);
}
ncstrcmp(s1, s2)
register ubyte *s1, *s2;
{
register ubyte c1, c2;
for (;;) {
c1 = *s1;
c2 = *s2;
if (c1 >= 'A' && c1 <= 'Z') c1 |= 0x20;
if (c2 >= 'A' && c2 <= 'Z') c2 |= 0x20;
if (c1 != c2)
break;
if ((c1|c2) == 0)
return(0);
++s1;
++s2;
}
if (c1 < c2)
return(-1);
if (c1 > c2)
return(1);
}
ED *
finded(str, doff)
char *str;
{
register ED *ed;
for (ed = (ED *)DBase.mlh_Head; ed->Node.mln_Succ; ed = (ED *)ed->Node.mln_Succ) {
if (strlen(ed->Name) >= doff && ncstrcmp(str, ed->Name+doff) == 0)
return(ed);
}
return(NULL);
}